package com.gw.smscheck.util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * 返回对象
 * @author ASUS
 *
 */
public class ResultObj {
	/**
	 * 成功的编码
	 */
	public static final int CODE_SUCCESS = 10001;
	/**
	 * 失败的编码
	 */
	public static int CODE_FAIL = 10002;
	/**
	 * 执行成功的消息
	 */
	public static String MSG_SUCCESS = "执行成功！";
	/**
	 * 执行失败的消息
	 */
	public static String MSG_FAIL = "执行失败！";
	
	/**
	 * 编码
	 */
	public int code;
	
	/**
	 * 数据
	 */
	public Object data;
	
	/**
	 * 消息
	 */
	public String msg;

	public ResultObj(){
		
	}
	
	public ResultObj(int code,String msg,Object data){
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	/**
	 * 成功返回
	 * @param data
	 * @return
	 */
	public static String successResultObj(Object data){
		return JSON.toJSONString(new ResultObj(ResultObj.CODE_SUCCESS,ResultObj.MSG_SUCCESS,data),SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullNumberAsZero,SerializerFeature.WriteNullListAsEmpty,SerializerFeature.WriteNullStringAsEmpty);
	}
	
	/**
	 * 失败返回
	 * @param data
	 * @return
	 */
	public static String failResultObj(Object data){
		return JSON.toJSONString(new ResultObj(ResultObj.CODE_FAIL,ResultObj.MSG_FAIL,data));
	}
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
